﻿using System;
using System.Drawing;
using System.Windows.Forms;
using LoLTimers.DataObjects;
using LoLTimers.Utilities;

namespace LoLTimers
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Exception ex = Settings.Instance.LoadSettingsXml(@"Settings.xml");
            if (ex != null)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK);
                return;
            }

            TimerManager.Instance.SetUpdateTimerInterval(Settings.Instance.SettingsData.UpdateTimerInterval);

            foreach (TimerDataObject tdo in Settings.Instance.SettingsData.TimerDataObjects)
            {
                TimerManager.Instance.RegisterTimer(new TimerDisplay(tdo));
            }

            TimerManager.Instance.StartTimers();
            
            Application.Run(new FrmMain());

            TimerManager.Instance.StopTimers();

            Settings.Instance.SaveSettingsXml();

            TimerManager.Instance.ClearTimers();
        }
    }
}
